import { userLogin } from "../../api/user"

export default {
	namespaced:true,
	state(){
		return {
			userInfo:null
		}
	},
	mutations:{
		loginSuccessMut(state,uinfo){
			console.log(11111,uinfo);
			state.userInfo = uinfo
			uni.setStorage({
				key:'uni-user-info',
				data:{...uinfo},
				success: (res) => {
					console.log(222,res);
				},
				fail: (err) => {
					console.log(3333,err);
				}
			})
		},
		initUserInfoMut(state){
			uni.getStorage({
				key:'uni-user-info',
				success: ({data}) => {
					if(data){
						state.userInfo = data
					}
				}
			})
		}
	},
	actions:{
		loginAction(context,info){
			userLogin(info).then(res=>{
				context.commit('loginSuccessMut',res.data)
				uni.navigateBack({
					delta:1
				})
			})
		}
	}
}